package com.lagou.edu.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * 自动发送简历Controller
 */
@RestController
@RequestMapping("/code")
public class AutoDeliverController {

    @Autowired
    private DiscoveryClient discoveryClient;

//    @Autowired
//    private RestTemplate restTemplate;

//    @GetMapping("/checkState/{userId}")
//    public Integer findResumeOpenState(@PathVariable Integer userId){
//
//        List<ServiceInstance> instancesList = discoveryClient.getInstances("lagou-service-resume");
//        ServiceInstance serviceInstance = instancesList.get(0);
//        String host = serviceInstance.getHost();
//        int port = serviceInstance.getPort();
//
//        Integer value = restTemplate.getForObject("http://"+host+":"+port+"/resume/openstate/"+userId, Integer.class);
//        return value;
//    }

    /**
     * ⽣生成验证码并发送到对应邮箱，
     * 成功true
     * 失败false
     * @param email
     * @return
     */
    @GetMapping("/create/{email}")
    public Boolean create(@PathVariable String email){
        System.out.println("email:"+email);
        return true;
    }

    /**
     * 校验验证码是否正确，0正确1错误2超时
     * @param email
     * @param code
     * @return
     */
    @GetMapping("/validate/{email}/{code}")
    public Integer validate(@PathVariable String email, @PathVariable String code){
        System.out.println("email:"+email);
        System.out.println("code:"+code);
        return 1;
    }
}
